package com.google.shoopinggoods.fragment;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import com.example.administrator.shoppinggoods.R;
import com.google.shoopinggoods.utils.Constant;
import java.util.ArrayList;
import butterknife.BindView;

/**
 * Created by Administrator on 2017/10/13.
 */
public class HomeFragment extends BaseFragment {
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    ArrayList<ViewPagerIndicatorAdapter.PageInfo> pageInfos = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.fragment_home;
    }

    @Override
    public void setListener() {
    }

    @Override
    public void loadData() {
        preparePageInfo();

        viewPager.setAdapter(new ViewPagerIndicatorAdapter(getChildFragmentManager(),pageInfos));

        tabLayout.setupWithViewPager(viewPager);

        stateLayout.showContentView();
    }

    //
    private void preparePageInfo() {
        //获取标题
        String[] title = getResources().getStringArray(R.array.goods_category);
        //添加每个标题界面
        pageInfos.add(new ViewPagerIndicatorAdapter.PageInfo(createFragment(Constant.GoodsCategory.Women),title[0]));
        pageInfos.add(new ViewPagerIndicatorAdapter.PageInfo(createFragment(Constant.GoodsCategory.Man),title[1]));
        pageInfos.add(new ViewPagerIndicatorAdapter.PageInfo(createFragment(Constant.GoodsCategory.Child),title[2]));
        pageInfos.add(new ViewPagerIndicatorAdapter.PageInfo(createFragment(Constant.GoodsCategory.Phone),title[3]));
        pageInfos.add(new ViewPagerIndicatorAdapter.PageInfo(createFragment(Constant.GoodsCategory.Book),title[4]));
    }

    private Fragment createFragment(String category){
        GoodsListFragment goodsListFragment = new GoodsListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(GoodsListFragment.CATEGORY,category);
        goodsListFragment.setArguments(bundle);
        return goodsListFragment;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
